package com.codeoss.module.res.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.codeoss.framework.service.impl.BaseService;
import com.codeoss.framework.util.StringUtils;
import com.codeoss.module.res.dao.ResUserMapper;
import com.codeoss.module.res.model.ResUser;
import com.codeoss.module.res.service.IResUserService;

@Service
public class ResUserService extends BaseService<ResUserMapper, ResUser> implements IResUserService {
	@Autowired
	private PasswordEncoder passwordEncoder;
	
	@Transactional
	public void insert(ResUser resUser) {
		String password=resUser.getPassword();
		if(StringUtils.isEmpty(password)) {
			password=passwordEncoder.encode("123456");
			resUser.setPassword(password);
		}
		super.insert(resUser);
	}

	@Override
	public ResUser getResUserByUsername(String username) {
		// TODO Auto-generated method stub
		QueryWrapper<ResUser> query=new QueryWrapper<ResUser>();
		query.eq("username", username);
		return getOne(query);
	}
}